package work20241126_27;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author zdl
 * @date 2024/11/26
 */
public class Demo31 {
    public static void main(String[] args) {
        //设计一个方法，找出数组中所有出现次数大于n次的元素
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个整数：");
        int num = sc.nextInt();
        test(num);
    }

    public static void test(int num) {
        int[] arr = {1,2,3,2,2,3};
        int count = 0;
        Arrays.sort(arr);
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] == arr[i-1]){//判断前后临近元素是否相同
                count++;
            }else {
                if (count > num){
                    System.out.println(arr[i-1]);
                }
                count = 1;
            }
            if (count > num){
                System.out.println(arr[arr.length-1]);
            }
        }

    }
}
